<?php
/**
 * 酒店
 * User: lxq
 * Date: 2018/3/15
 * Time: 10:37
 */
class hotelModel extends  Model {

    public function __construct()
    {
        parent::__construct('hotel');
    }

    /**
     * 获取列表分页
     * @param array $condition
     * @param string $field
     * @param int $page
     * @param string $order
     * @return mixed
     */
    public function getHotelListPage($condition = array(), $field = '*', $page = null, $order = 'ht_update_time desc'){
        return $this->where($condition)->field($field)->page($page)->order($order)->select();
    }

//    public function getHotelList($condition = array(), $field = '*', $page = 0, $order = 'store_id desc'){
//        return $this->where($condition)->field($field)->page($page)->order($order)->select();
//    }
    /**
     * 获取一条记录的详细信息
     * @param array $condition
     * @param string $field
     * @return mixed
     */
    public function getHotelInfo($condition = array(), $field = '*')
    {
        return $this->field($field)->where($condition)->find();
    }

    /**
     * 插入一条记录
     * @param array $params
     * @return mixed
     */
    public function addHotel($params)
    {
        return $this->insert($params);
    }

    /**
     * 更新记录
     * @param array $condition
     * @param array $params
     * @return mixed
     */
    public function updateHotel($condition, $params)
    {
        return $this->where($condition)->update($params);
    }

    /**
     *  删除记录
     * @param array $condition
     */
    public function deleteHotel($condition)
    {
        return $this->where($condition)->delete();
    }

    /**
     * 获取记录数组
     * @param array $condition
     * @param string $field
     * @param string $order
     * @return mixed
     */
    public function getHotelList($condition = array(), $field = '*', $order = 'id desc'){
        return $this->field($field)->where($condition)->order($order)->select();
    }

    /**
     * 获取所有商品分类的城市ID（去重复）
     */
    public function getHotelCityId()
    {
        $city_list =  $this->where(array('ht_status'=>1))->field('ht_city_id')->group('ht_city_id')->select();
        /*if($city_list && is_array($city_list)){
            $arr = array();
            foreach($city_list as $key=>$value){
                $arr[$value['ht_city_id']][] =$value['ht_area_id'];
            }
            return $arr;

        }*/
        return $city_list;
    }

    /**
     * 获取所有商品分类的城市ID（去重复）
     */
    public function getHotelAreaId()
    {
        $city_list =  $this->where(array('ht_status'=>1))->field('ht_area_id')->group('ht_area_id')->select();
        /*if($city_list && is_array($city_list)){
            $arr = array();
            foreach($city_list as $key=>$value){
                $arr[$value['ht_city_id']][] =$value['ht_area_id'];
            }
            return $arr;

        }*/
        return $city_list;
    }

    /**
     * 取得数量
     * @param array $condition
     */
    public function getHotelCount($condition) {
        return $this->table('hotel')->where($condition)->count();
    }


    public function get_status_count($condition){
        $field = "count(ht_status=1 or null ) as 'sale_count', count(ht_status=0 or null ) as 'un_sale_count' ";
        return $this->field($field)->where($condition)->find();
    }



}